'use strict';

const BaseService = require('./base');

class PersonService extends BaseService {
  get _model() {
    return 'Person';
  }

  async findOne({ id }) {
    const where = this.formatWhere({ exact: { id } });
    return this._findOne({ where });
  }

  async create({ name, No, isMy, uid }) {
    return this._create({
      name, No, isMy, uid,
    });
  }

  async update({ name, No, isMy, uid, id }) {
    const where = this.formatWhere({ exact: { uid, id } });
    const body = { name, No, isMy };
    return this._update({ body, where });
  }

  async destory(id) {
    const where = { id };
    return this._destory({ where });
  }

  async findList({ pageIndex, pageSize, uid }) {
    const where = this.formatWhere({ exact: { uid } });
    return this._findList({ pageIndex, pageSize, where });
  }

  async findAll({ ids, uid } = {}) {
    let where = {};
    if (ids) {
      where = this.formatWhere({ inOp: { id: ids.split(',') } });
    } else {
      where = this.formatWhere({ exact: { uid } });
    }
    const attributes = [ 'id', 'name', 'No' ];
    return this._findAll({ where, attributes });
  }
}

module.exports = PersonService;
